package com.keshi.openplatform.payment.controller;

import com.keshi.openplatform.payment.utils.PayCommonUtil;
import com.keshi.openplatform.payment.utils.ZxingUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.util.UUID;

@Controller
@RequestMapping("/payment")
public class OrderController {


    @RequestMapping("/createorder")
    public String createOrder(String body, ModelMap modelMap, HttpSession session){
        UUID uuid = UUID.randomUUID();
        String oid = uuid.toString().replaceAll("-", "");//订单id
        try {
            String wxurl = PayCommonUtil.weixin_pay("1", body, oid);//发起请求并获取支付的二维码的字符串内容

            BufferedImage image = ZxingUtil.createImage(wxurl, 300, 300);
            modelMap.put("orderid", oid);
            session.setAttribute("img",image);//我们将生成的图片保存到session中,通过请求再获取一下
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "payment";

    }

    public static void main(String[] args) {
        UUID uuid = UUID.randomUUID();
        System.err.println(uuid);
    }
}
